package com.etogc.util;

import android.app.Activity;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

/**
 * 获得屏幕的长和宽
 * 
 * @author chenxiang
 * 
 */
public class ScreenUtil {
	private static ScreenUtil screenUtil;
	public static ScreenUtil getInstance(){
		if(screenUtil==null){
			screenUtil = new ScreenUtil();
		}
		return screenUtil;
	}
	/** 是否开启全屏 */
	private boolean isFullScreen = false;
	public  int getWindowWidth(Context myContext) {
		WindowManager wm = (WindowManager) myContext
				.getSystemService(Context.WINDOW_SERVICE);

		return wm.getDefaultDisplay().getWidth();
	}

	public  int getWindowHeight(Context myContext) {
		WindowManager wm = (WindowManager) myContext
				.getSystemService(Context.WINDOW_SERVICE);

		return wm.getDefaultDisplay().getHeight();
	}

	/** 设置键盘不显示 */
	public void hideSoftInput(Context context) {
		((Activity)context).getWindow().setSoftInputMode(
				WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
	}

	/** 是否开启全屏 */
	public void setFullScreen(boolean isFullScreen) {
		this.isFullScreen = isFullScreen;
	}

	/** 开启全屏 */
	public void openFullScreen(Context context) {
		if (isFullScreen) {
			((Activity)context).requestWindowFeature(Window.FEATURE_NO_TITLE);
			((Activity)context).requestWindowFeature(Window.FEATURE_PROGRESS);
		}
	}
	/**
	 * 获取屏幕的宽度
	 *
	 * @param context
	 * @return
	 */
	public static int getScreenWidth(Context context) {
		WindowManager manager = (WindowManager) context
				.getSystemService(Context.WINDOW_SERVICE);
		Display display = manager.getDefaultDisplay();
		return display.getWidth();
	}

	/**
	 * 获取屏幕的高度
	 *
	 * @param context
	 * @return
	 */
	public static int getScreenHeight(Context context) {
		WindowManager manager = (WindowManager) context
				.getSystemService(Context.WINDOW_SERVICE);
		Display display = manager.getDefaultDisplay();
		return display.getHeight();
	}

	/**
	 * 获取屏幕中控件顶部位置的高度--即控件顶部的Y点
	 *
	 * @return
	 */
	public static int getScreenViewTopHeight(View view) {
		return view.getTop();
	}

	/**
	 * 获取屏幕中控件底部位置的高度--即控件底部的Y点
	 *
	 * @return
	 */
	public static int getScreenViewBottomHeight(View view) {
		return view.getBottom();
	}

	/**
	 * 获取屏幕中控件左侧的位置--即控件左侧的X点
	 *
	 * @return
	 */
	public static int getScreenViewLeftHeight(View view) {
		return view.getLeft();
	}

	/**
	 * 获取屏幕中控件右侧的位置--即控件右侧的X点
	 *
	 * @return
	 */
	public static int getScreenViewRightHeight(View view) {
		return view.getRight();
	}

	/**
	 * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
	 */
	public int dip2px(Context context,float dpValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (dpValue * scale + 0.5f);
	}
}
